using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;

namespace Lds.Ward.PhotoDirectory.Logic
{
	public class PhoneNumber
	{
		public const string RegEx = @"\s*(?<phone>(?<areacode>\d{3})?[- \.()]*(?<prefix>\d{3})[- \.()]*(?<suffix>\d{4}))";

		public PhoneNumber() { }
		public PhoneNumber(string original)
		{
			Original = original;
		}

		private string original;

		public string Original
		{
			get { return original; }
			private set { original = value; }
		}

		protected Match Match
		{
			get { return Regex.Match(Original, RegEx); }
		}

		public string AreaCode
		{
			get { return Match.Groups["areacode"].Value; }
		}
		public string Prefix
		{
			get { return Match.Groups["prefix"].Value; }
		}
		public string Suffix
		{
			get { return Match.Groups["suffix"].Value; }
		}
		public override string ToString()
		{
			return string.Format("{0}{1}{2}-{3}", AreaCode, 
				AreaCode != null && AreaCode.Length > 0 ? "-" : "", Prefix, Suffix);
		}
	}
}
